def func(l, n):
    l.sort()
    right = len(l)-1
    left = 0
    while left <= right:
        middle = int((left+right)/2)
        if n < l[middle]:
            right = middle - 1

        elif n > l[middle]:
            left = middle + 1

        else:
            return middle

    return -1



a = [1, 2, 3, 4, 5, 6]
a.sort()
print(func(a, 9))

print(int(2.99))    # 取整（不会四舍五入）